package com.zuthub.web.controller.system;

import java.util.HashMap;
import java.util.List;

import com.zuthub.system.domain.SysHonor;
import com.zuthub.web.controller.tool.OssUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysVideo;
import com.zuthub.system.service.ISysVideoService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 视频管理Controller
 * 
 * @author zuthub
 * @date 2021-05-04
 */
@RestController
@RequestMapping("/system/video")
public class SysVideoController extends BaseController
{
    @Autowired
    private ISysVideoService sysVideoService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 查询视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:video:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVideo sysVideo)
    {
        startPage();
        List<SysVideo> list = sysVideoService.selectSysVideoList(sysVideo);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo tourist(SysVideo sysVideo)
    {
        startPage();
        List<SysVideo> list = sysVideoService.selectSysVideoList(sysVideo);
        return getDataTable(list);
    }

    /**
     * 导出视频管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:video:export')")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysVideo sysVideo)
    {
        List<SysVideo> list = sysVideoService.selectSysVideoList(sysVideo);
        ExcelUtil<SysVideo> util = new ExcelUtil<SysVideo>(SysVideo.class);
        return util.exportExcel(list, "video");
    }

    /**
     * 获取视频管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:video:query')")
    @GetMapping(value = "/{videoId}")
    public AjaxResult getInfo(@PathVariable("videoId") Long videoId)
    {
        return AjaxResult.success(sysVideoService.selectSysVideoById(videoId));
    }

    /**
     * 新增视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:video:add')")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVideo sysVideo)
    {
        return toAjax(sysVideoService.insertSysVideo(sysVideo));
    }


    @PostMapping("upload")
    public AjaxResult upload(MultipartFile file)
    {
        String path = ossUtils.uploadVideo(file);
        String fileName = file.getOriginalFilename();
        HashMap<String, String> map = new HashMap<>();
        map.put("url", path);
        map.put("fileName",fileName);
        return AjaxResult.success(map);
    }

    /**
     * 修改视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:video:edit')")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVideo sysVideo)
    {
        return toAjax(sysVideoService.updateSysVideo(sysVideo));
    }

    /**
     * 删除视频管理
     */
    @PreAuthorize("@ss.hasPermi('system:video:remove')")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{videoIds}")
    public AjaxResult remove(@PathVariable Long[] videoIds)
    {
        return toAjax(sysVideoService.deleteSysVideoByIds(videoIds));
    }
}
